<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
      class="query-form"
    >
      <el-form-item label="隧道名称" prop="equName">
        <el-input
          v-model="queryParams.equName"
          placeholder="请输入隧道名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="equName">
        <el-select v-model="form.equType" placeholder="请选择设备类型">
          <el-option label="PLC" value="1" />
          <el-option label="风机" value="2" />
          <el-option label="灯组" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="handleQuery">查询</el-button>
        <el-button size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="content-container height_100-query_from">
      <div class="handle_bar">
        <div class="tit"><span>设备列表</span></div>
        <el-button
          type="primary"
          plain
          size="small"
          @click="handleAdd"
        >新增</el-button>
      </div>
      <div class="flex-1" style="position: relative;overflow: hidden;">
        <div style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;display: flex;flex-direction: column;overflow: hidden;">
          <el-table
            v-loading="loading"
            class="flex-1"
            height="250"
            style="width:100%;"
            :data="equList"
            @selection-change="handleSelectionChange"
          >
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <!-- <el-table-column label="ID" align="center" prop="id" /> -->
            <el-table-column label="隧道名称" align="center" prop="sdmc" />
            <el-table-column label="设备名称" align="center" prop="sbmc" />
            <el-table-column label="品牌/型号" align="center" prop="fjpp" />
            <!-- <el-table-column label="型号" align="center" prop="supplier" /> -->
            <!-- <el-table-column label="供应商" align="center" prop="supplier" />
            <el-table-column label="规格型号" align="center" prop="brand" />
            <el-table-column label="购入价格" align="center" prop="price" />
            <el-table-column label="生产日期" align="center" prop="produceDate" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.produceDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="质保期" align="center" prop="warranty" /> -->
            <el-table-column label="ip地址" align="center" prop="ip" />
            <!-- <el-table-column label="灯组类型" align="center" prop="lightType" />
          <el-table-column label="类型" align="center" prop="equType" /> -->
            <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button
                  v-hasPermi="['lc:equ:edit']"
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                >修改</el-button>
                <el-button
                  v-hasPermi="['lc:equ:remove']"
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 添加或修改设备定义对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body :fullscreen="true">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" size="small">
        <div style="display:inline-block;width: 40%;float: left;">
          <fieldset>
            <legend>风机</legend>
            <el-form-item label="风机名称" prop="fjmc">
              <el-input v-model="form.fjmc" placeholder="请输入风机名称" />
            </el-form-item>
            <el-form-item label="风机品牌及型号" prop="fjpp" label-width="110px">
              <el-select v-model="form.fjpp" style="width:100%;">
                <el-option label="中隧 SDS-90K-4PD3 Y4-15" value="中隧 SDS-90K-4PD3 Y4-15" />
                <el-option label="科禄格 KJF-1120-R-1D" value="科禄格 KJF-1120-R-1D" />
                <el-option label="南方风机 NSL-112R-4P-37" value="南方风机 NSL-112R-4P-37" />
                <el-option label="浙江双阳 SDS(R)-11.2" value="浙江双阳 SDS(R)-11.2" />
              </el-select>
            </el-form-item>
            <el-form-item label="Ip地址" prop="fjip">
              <el-input v-model="form.fjip" placeholder="请输入风机名称" />
            </el-form-item>
          </fieldset>
          <fieldset>
            <legend>PLC</legend>
            <el-form-item label="PLC名称" prop="plcmc">
              <el-input v-model="form.plcmc" placeholder="请输入风机名称" />
            </el-form-item>
            <el-form-item label="PLC品牌" prop="plcpp" label-width="110px">
              <el-select v-model="form.plcpp" style="width:100%;">
                <el-option label="西门子" value="西门子" />
                <el-option label="欧姆龙" value="欧姆龙" />
                <el-option label="三菱" value="三菱" />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="PLC型号" prop="plcxh">
              <el-select v-model="form.plcxh" style="width:100%;">
                <template v-if="form.prcpp == '西门子'">
                  <el-option label="S7-200" value="S7-200" />
                  <el-option label="S7-300" value="S7-300" />
                  <el-option label="S7-400" value="S7-400" />
                  <el-option label="S7-1200" value="S7-1200" />
                  <el-option label="S7-1500" value="S7-1500" />
                </template>
                <template v-if="form.prcpp == '欧姆龙'">
                  <el-option label="NX7" value="NX7" />
                  <el-option label="NX1" value="NX1" />
                  <el-option label="NX1P" value="NX1P" />
                  <el-option label="NJ" value="NJ" />
                  <el-option label="CP" value="CP" />
                  <el-option label="CJ1" value="CJ1" />
                  <el-option label="CJ2" value="CJ2" />
                  <el-option label="CS1" value="CS2" />
                  <el-option label="C200HX" value="C200HX" />
                  <el-option label="C200HG" value="C200HG" />
                  <el-option label="C200HE" value="C200HE" />
                  <el-option label="CPM" value="CPM" />
                </template>
                <template v-if="form.prcpp == '三菱'">
                  <el-option label="FX1S" value="FX1S" />
                  <el-option label="FX1N" value="FX1N" />
                  <el-option label="FX2N" value="FX2N" />
                  <el-option label="FX3U" value="FX3U" />
                  <el-option label="FX3G" value="FX3G" />
                </template>
              </el-select>
            </el-form-item> -->
            <el-form-item label="Ip地址" prop="plcip">
              <el-input v-model="form.plcip" placeholder="请输入风机名称" />
            </el-form-item>
          </fieldset>
        </div>
        <div style="width:60%;float: left;">
          <fieldset>
            <legend>数据库</legend>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="数据库类型" :prop="sqlType">
                  <!-- <el-input v-model="form.sqlType" /> -->
                  <el-select v-model="form.sqlType" style="width:100%;">
                    <el-option label="Oracle" value="Oracle" />
                    <el-option label="MySql" value="MySql" />
                    <el-option label="SQLserver" value="SQLserver" />
                    <el-option label="DM" value="DM" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item class="form-item__lable_100">
                  <div slot="label">
                    数据源
                    <el-tooltip placement="bottom-start" effect="light">
                      <div slot="content">
                        第一行信息<br>
                        第二行信息
                      </div>
                      <i class="el-icon-question" />
                    </el-tooltip>
                    <el-link class="fr" type="primary">管理</el-link>
                  </div>
                  <el-input v-model="form.bb" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="JDBC连接URL">
                  <el-input v-model="form.jdbc" placeholder="请输入JDBC连接URL" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="用户名">
                  <el-input v-model="form.username" placeholder="请输入用户名" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="密码">
                  <el-input v-model="form.pwd" placeholder="请输入密码" />
                </el-form-item>
              </el-col>
            </el-row>
            <div class="flex-row" style="line-height:1.5em;">
              <label class="flex-0">注：</label>
              <div class="flex-1">
                <p>Oracle：<span class="text-danger">jdbc:oracle:thin:@数据库地址:端口:orcl</span></p>
                <p>Mysql：<span class="text-danger">jdbc:mysql://数据库地址:端口/数据库名</span></p>
                <p>SQLServer：<span class="text-danger">jdbc:sqlserver://数据库地址:端口:DataseName=数据库名</span></p>
              </div>
            </div>
          </fieldset>
        </div>
        <div style="clear: both;" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEqu, getEqu, delEqu, addEqu, updateEqu } from '@/api/fjgs/equ'
import { listAll } from '@/api/system/tunnel'
export default {
  name: 'Equ',
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 10,
      // 设备定义表格数据
      equList: [
        {
          sdmc: '小营特长隧道（上行）',
          sbmc: '上行风机1号',
          fjpp: '中隧 SDS-90K-4PD3 Y4-15',
          ip: '10.254.0.65'
        },
        {
          sdmc: '小营特长隧道（上行）',
          sbmc: '上行风机2号',
          fjpp: '中隧 SDS-90K-4PD3 Y4-15',
          ip: '10.254.0.66'
        },
        {
          sdmc: '小营特长隧道（上行）',
          sbmc: '上行风机8号',
          fjpp: '中隧 SDS-90K-4PD3 Y4-15',
          ip: '10.254.0.67'
        },
        {
          sdmc: '小营特长隧道（下行）',
          sbmc: '下行风机9号',
          fjpp: '中隧 SDS-90K-4PD3 Y4-15',
          ip: '10.254.0.68'
        },
        {
          sdmc: '小营特长隧道（下行）',
          sbmc: '下行PLC',
          fjpp: '西门子',
          ip: '10.254.0.69'
        }
      ],
      tunnelAll: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equName: null,
        locationName: null,
        produceCompany: null,
        supplier: null,
        brand: null,
        price: null,
        produceDate: null,
        warranty: null,
        ip: null,
        lightType: null,
        equType: ''
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      formLabelAlign: {
        aa: '',
        bb: '',
        cc: '',
        dd: ''
      }
    }
  },
  created() {
    // this.getList()
    listAll().then(res => {
      this.tunnelAll = res.data
    })
  },
  methods: {
    /** 查询设备定义列表 */
    getList() {
      this.loading = true
      listEqu(this.queryParams).then(response => {
        this.equList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equName: null,
        locationName: null,
        produceCompany: null,
        supplier: null,
        brand: null,
        price: null,
        produceDate: null,
        warranty: null,
        ip: null,
        lightType: null,
        equType: 1
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加设备定义'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getEqu(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改设备定义'
      })
    },
    /** 提交按钮 */
    // submitForm() {
    //   this.$refs['form'].validate(valid => {
    //     if (valid) {
    //       if (this.form.id != null) {
    //         updateEqu(this.form).then(response => {
    //           this.msgSuccess('修改成功')
    //           this.open = false
    //           this.getList()
    //         })
    //       } else {
    //         addEqu(this.form).then(response => {
    //           this.msgSuccess('新增成功')
    //           this.open = false
    //           this.getList()
    //         })
    //       }
    //     }
    //   })
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除设备定义编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delEqu(ids)
      }).then(() => {
        this.getList()
        this.msgSuccess('删除成功')
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lc/equ/export', {
        ...this.queryParams
      }, `lc_equ.xlsx`)
    }
  }
}
</script>
<style lang="scss">
fieldset {
//  border: 1px solid #7F9DB9;
}
  .tabs-full {
    // background-color:#fff;
    // display: flex;
    // flex-direction: column;
    // ::v-deep .el-tabs__header {
    //   flex-grow:0;
    //   flex-shrink:0;
    //   flex-basis:auto;
    // }
    ::v-deep .el-tabs__content {
      height: calc(100% - 62px);
      // position: relative;
      // flex: 1;
      .el-tab-pane {
        // position: absolute;
        width: 100%;
        height: 100%;
        // left: 0;
        // top: 0;
        // right: 0;
        // bottom: 0;
      }
    }
  }
  .content {
    width:864px; margin:0 auto;
    padding-bottom: 40px;
  }
  .form-item__lable_100 {
    ::v-deep .el-form-item__label {
      width:100%;
    }
  }
  .dashed {
    margin: 24px 0;
    border-top: 2px dashed #eee;;
  }
</style>
<style lang="scss">
.wttec-form {
    // .el-form-item {
    //     display: inline-block;
    // }
  .el-form-item__label {
    padding-bottom: 4px;
  }
  .el-checkbox {
    margin-right: 12px;
    &:last-child {
      margin-right: 0;
    }
  }
  .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color:#666;//inherit
  }
  .item-text,.read-only {
    margin: 0;
    padding: 0 16px;
    line-height: 36px;
    background-color: #f4f5f9;
    border-radius: 4px;
    &:empty {
      &::before{
        display: block;
        content: '\2002';
      }
    }
    // read-only

  }
}
</style>
